from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser

llm = ChatOpenAI(
    openai_api_base="https://api.openai-proxy.org/v1",
    openai_api_key="sk-N7HqBKMQJE8FFZ1y0m5GZielsPWFATIOSGoG82zG0k2gQI9f",
)

prompt = ChatPromptTemplate.from_messages(
    [("system", "你是世界级技术专家"), ("user", "{input}")]
)

output_parser = StrOutputParser()

chain = prompt | llm | output_parser


def invoke_open_ai(input):
    result = chain.invoke({"input": input})
    return result
